﻿@using ETD.Common.Extension;
@using ETD.WebManagement.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@model ETD.WebManagement.Areas.Web.Models.WpSecurityItemModel
@{
    ViewBag.Title = "安检表";
}
@{
    var wpSecurityItem = Model.UIWpSecurityItem;
}
<style>
    .text-left {
        text-align: left;
    }

    .securityCheckItem-name {
        font-size: 16px !important;
        line-height: 2 !important;
    }

    .weui-form-preview:after {
        border-bottom: 0px solid #e5e5e5 !important;
    }
</style>
<div class="weui-form-preview">

    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
        <div class="weui-cell__bd">
            <span class="weui-form-preview__value text-left" style="">@wpSecurityItem.HiddenDangerContent</span>
        </div>
    </div>

    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">当前状态</label></div>
        <div class="weui-cell__bd">
            <span class="weui-form-preview__value text-left" style="">@wpSecurityItem.WpSecurityItemStatusRealText</span>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">检查结果</label></div>
        <div class="weui-cell__bd">
            <textarea id="txtCheckResultInfo" class="weui-textarea weui-form-preview__value" placeholder="请输入检查结果" rows="3">@wpSecurityItem.CheckResultInfo</textarea>
        </div>
    </div>


    @if (wpSecurityItem.WpSecurityItemStatusID == (int)EWpSecurityItemStatus.CheckPass || wpSecurityItem.WpSecurityItemStatusID == (int)EWpSecurityItemStatus.CheckNotPass)
    {
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">检查时间</label></div>
            <div class="weui-cell__bd">
                <span class="weui-form-preview__value text-left" style="">@wpSecurityItem.CheckDateTime.ToDefaultDT()</span>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">检查人</label></div>
            <div class="weui-cell__bd">
                <span class="weui-form-preview__value text-left" style="">@(wpSecurityItem.UserName)(@wpSecurityItem.RealName)</span>
            </div>
        </div>

    }
    @if (wpSecurityItem.WpSecurityItemStatusID == (int)EWpSecurityItemStatus.NotCheck)
    {
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="btnCheckQualified" class="weui-btn weui-btn_primary">检验合格</a>
                <a href="javascript:;" id="btnCheckUnqualified" class="weui-btn weui-btn_default">检验不合格</a>
            </p>
        </div>
    }
</div>
@section ScriptSection{
    <script>
        $(function () {
            $("#btnCheckQualified").click(confirmCheckQualified);
            $("#btnCheckUnqualified").click(confirmCheckUnqualified);
        });
        function confirmCheckQualified() {
            $.confirm("确定检验合格吗?", "确认?", function () {
                //$.toast("文件已经删除!");
                checkQualified(function(){
                    setTimeout(function () {
                        window.location.href="@Url.Action("TodayTask", "Security")"; }, 1000);
                });

            }, function () {
                //取消操作
            });
        }
        function confirmCheckUnqualified() {
            $.confirm("确定检验不合格吗?", "确认?", function () {
                checkUnqualified(function(){
                    setTimeout(function () {
                        window.location.href="@Url.Action("TodayTask", "Security")"; }, 1000);
                });
            }, function () {
                //取消操作
            });
        }
        function checkQualified(callBack) {
            var paras = {};
            paras.WpSecurityItemID = @wpSecurityItem.WpSecurityItemID;
            paras.CheckResultInfo = $("#txtCheckResultInfo").val();
            ajaxPost("@Url.Action("CheckQualified", "Security")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast("操作完成!");
                    callBack();
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }
        function checkUnqualified(callBack) {
            var paras = {};
            paras.WpSecurityItemID = @wpSecurityItem.WpSecurityItemID;
            paras.CheckResultInfo = $("#txtCheckResultInfo").val();

            if(!paras.CheckResultInfo.trim()){
                $.toptip('检查不合格必须填写结果', 'warning');
                return;
            }

            ajaxPost("@Url.Action("CheckUnqualified", "Security")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast("操作完成!");
                    callBack();
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }

    </script>
}
